<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
?>

<script language="javascript" type="text/javascript">
function tableOrdering( order, dir, task )
{
        var form = document.adminForm;
        form.filter_order.value = order;
        form.filter_order_Dir.value = dir;
        document.adminForm.submit( task );
}
</script> 

<?php if ($this->params->get( 'show_page_title', 1 ) && $this->params->get('page_title') != '' ) : ?>
	<div class="componentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
		<?php echo $this->params->get( 'page_title' ).' <span class="sstav">('.JText::_('STAV_KU_DNU').' '.StrFTime("%d.%m.%Y", Time()).')</span>'; ?>
  </div>
<?php endif; ?>

<?php echo "<!-- jZmluvy ver.".$this->nastavenie->ver." START -->"; ?>

<form action="<?php echo JRoute::_( 'index.php' );?>" method="post" name="adminForm" id="adminForm" class="form-validate">

<?php // vyvolanie filtra ?>
<?php echo $this->params->get( 'filter') ? '<div id="filter">'.$this->loadTemplate('filter').'</div>':''; ?> 

<table id="jzmluvy">

 <thead>
	<?php $f=8; if($this->params->get( 'detail') == 0): // ak je DETAIL vypnuty tak su zobrazene vsetky povinne udaje?>
	<tr class="heading">
		<?php if($this->params->get( 'datZverejnania')): ?>
		<th>
			<?php echo JHTML::_( 'grid.sort', JText::_('DAT_ZVER'), 'datZver', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th><?php $f++; endif; ?>
		<th>
			<?php echo JHTML::_( 'grid.sort', JText::_('DAT_UZAVRETIA'), 'datUhrady', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>
		<?php if($this->params->get( 'cisloZml')): ?>
		<th>
			<?php echo JHTML::_( 'grid.sort', JText::_('CISLO_ZML'), 'faktura', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th><?php $f++; endif; ?>
		<th class="popisPlneniaObj">
			<?php echo JHTML::_( 'grid.sort', JText::_('POPIS_PLNENIA_ZML'), 'ud.fulltext', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>      
		<th>
			<?php echo JHTML::_( 'grid.sort', JText::_('SUMA'), 'suma', $this->lists['order_Dir'], $this->lists['order']); ?> 
			<?php echo $this->nastavenie->dph ? '&nbsp;'.JText::_('S_DPH') : '&nbsp;'.JText::_('BEZ_DPH'); ?>      
		</th>     
		<th>
			<?php echo  JHTML::_( 'grid.sort', JText::_('ZML_DOD'), 'typ', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>
		<th>
			<?php echo  JHTML::_( 'grid.sort', JText::_('DODAVATEL'), 'dodavatel', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>
		<th>
			<?php echo  JHTML::_( 'grid.sort', JText::_('ICO'), 'ico', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>
		<th>
			<?php echo  JHTML::_( 'grid.sort', JText::_('ADRESA'), 'mesto', $this->lists['order_Dir'], $this->lists['order']); ?>
		</th>    
		<th>
			<?php echo   JText::_('DOKUMENTY'); ?>
		</th>
	</tr>
	<?php else : $f=5; // zapnuty  DETAIL ?>
  <tr class="heading">
    <?php if($this->params->get( 'datZverejnania')): ?>
		<th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_ZVER'), 'datZver', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <?php if($this->params->get( 'datUzavretia')): ?>
		<th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_UZAVRETIA'), 'datUhrady', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <?php if($this->params->get( 'cisloZml')): ?>
		<th>
      <?php echo JHTML::_( 'grid.sort', JText::_('CISLO_ZML'), 'faktura', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
		<th>
      <?php echo JHTML::_( 'grid.sort', JText::_('POPIS_PLNENIA_ZML'), 'ud.fulltext', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('SUMA'), 'suma', $this->lists['order_Dir'], $this->lists['order']); ?> 
      <?php echo $this->nastavenie->dph ? '&nbsp;'.JText::_('S_DPH') : '&nbsp;'.JText::_('BEZ_DPH'); ?>      
    </th>      
		<th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ZML_DOD'), 'typ', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
		<th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('DODAVATEL'), 'dodavatel', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <?php if($this->params->get( 'ico')): ?>
		<th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ICO'), 'ico', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <?php if($this->params->get( 'adresa')): ?>
		<th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ADRESA'), 'mesto', $this->lists['order_Dir'], $this->lists['order']); ?>
      </th><?php $f++; endif; ?>    
    <?php if($this->params->get( 'dokumenty')): ?>
		<th>
      <?php echo   JText::_('DOKUMENTY'); ?>
    </th><?php $f++; endif; ?>
  </tr>
  <?php endif; ?>  
 </thead> 

  <tfoot>
    <tr>
      <td colspan="<?php echo $f; ?>">
        <div class="foot">
          <span class="left">
            <?php echo $this->pagination->getPagesLinks(); ?>&nbsp;
          </span>
          <span class="right">
            <?php echo $this->pagination->getPagesCounter(); ?>
            <?php echo $this->pagination->getLimitBox(); ?>
          </span>
        </div>
      </td>
    </tr>
  </tfoot>
  
  <tbody>
  <?php $k = 0; $stat="";
  foreach ($this->items AS $item) :
  $k++; $e=$k%2;
  $adresa = $item->ulica.",".$item->psc."  ".$item->mesto; 
  if($this->params->get( 'zobr_stat')) { $stat = ", ".$item->stat; }
  $link  = 'index.php?option=com_jzmluvy&view=zmluvy&task=download&id='.$item->id;
  $link2 = 'index.php?option=com_jzmluvy&view=zmluvy&task=download2&id='.$item->id;
  $link_detail = 'index.php?option=com_jzmluvy&view=zmluvy&task=detail&id='.$item->id;
  //$link_dod = 'index.php?option=com_jzmluvy&view=faktury&layout=dodavatel&id='.$item->id
  $link_dod = '#';
  $link_zml = 'index.php?option=com_jzmluvy&view=zmluvy&layout=detail&id='.$item->sposob_uhrady;;
  // ak nie je vyplneny datum zverejnenia tak NIC
  if($item->datZver == "0000-00-00") { $item->datZver = ''; }
  ?>
           
    <?php if($this->params->get( 'detail') == 0): // ak je DETAIL vypnuty tak su zobrazene vsetky povinne udaje?>
    <tr class="vypis<?php echo $e; ?>">    
      <?php if($this->params->get( 'datZverejnania')): ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datZver) ?>
    </td><?php endif; ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datUhrady) ?>
    </td>
    <?php if($this->params->get( 'cisloZml')): ?>
    <td>
      <?php echo $item->faktura ?>
    </td><?php endif; ?>
    <td>
      <div>
        <?php echo $item->fulltext ?>
      </div>
      <div>
        <?php echo $item->title ?>
      </div>
    </td>
    <td class="right">
      <?php echo jzmluvyHelper::fsuma($item->suma,$item->mena) ?>
    </td>
    <?php // typ zmluvy ?>
    <?php if(!$item->typ_zml) : $item->typ_zml = $item->typ_zml2; endif; ?>
    <td>
      <div>
        <?php echo typ_zml_dod($item->typ) ?>
      </div>
    <?php if($this->params->get( 'identDod') == 2 && !empty($item->typ_zml)): ?>
      <div>
        <a href="<?php echo $link_zml ?>"><?php echo $item->typ_zml ?></a>
      </div>
    <?php elseif($this->params->get( 'identDod') == 1 && !empty($item->typ_zml)) : ?>
      <div>
        <?php echo $item->typ_zml." "; ?>
      </div>
      <?php endif; ?>
    </td>
    <td>
      <?php if($this->params->get( 'dodavatel')): ?>
      <a href="<?php echo $link_dod ?>">
        <?php echo $item->fadod ?>
      </a>
      <?php else : ?>
      <?php echo $item->fadod ?>
      <?php endif; ?>
    </td>
    <td>
      <?php echo $item->ico ?>
    </td>
    <td>
      <?php echo $adresa.$stat ?>
    </td>
    <td class="center">
      <?php if(!empty($item->file)) { ?>
      <?php echo  jzmluvyHelper::subor_scan($item->id,$item->file,$item->filename,$item->extension,$link,$item->hits,0); }?> 
      <?php if(!empty($item->file2)) { ?>
      <?php echo  jzmluvyHelper::subor_text($item->id,$item->file2,$item->filename2,$item->extension2,$link2,$item->hits2,0); ?>
      <?php } ?>&nbsp;
    </td>
  </tr>
  <?php else : // zapnuty detail ?>
  <tr class="vypis<?php echo $e; ?>">
    <?php if($this->params->get( 'datZverejnania')): ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datZver) ?>
    </td><?php endif; ?>
    <?php if($this->params->get( 'datUzavretia')): ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datUhrady) ?>
    </td><?php endif; ?>
    <?php if($this->params->get( 'cisloZml')): ?>
    <td>
      <?php echo $item->faktura ?>
    </td><?php endif; ?>
    <td>
      <div>
        <a href="<?php echo $link_detail ?>">
          <?php echo $item->fulltext ?>
          <img src="components/com_jzmluvy/assets/images/detail.gif" height="14" width="14" title="Detail" alt="Detail" />
        </a>
      </div>
      <div>
        <?php echo $item->title ?>
      </div>
    </td>
    <td class="right">
      <?php echo jzmluvyHelper::fsuma($item->suma,$item->mena) ?>
    </td>
    <td>
      <div>
        <?php echo typ_zml_dod($item->typ); ?>
      </div>
    </td>
    <?php if($this->params->get('podpis') != 0) : ?>
    <?php if($this->params->get('kontakty') == 0): ?>
    <td>
      <div>
        <?php echo $item->vlastni1 ?>
      </div>
      <div>
        <?php echo $item->vlastni2 ?>
      </div>
    </td>
  	<?php else: ?>
    <td>
      <div>
      <?php if($this->params->get( 'podpis') == 2): ?>
        <a href="<?php echo $link_podpis ?>">
          <?php echo $item->kontakt ?>
        </a>
        <?php else : ?>
        <?php echo $item->kontakt ?>
        <?php endif; ?>
      </div>
      <div>
        <?php echo $item->pozicia ?>
      </div>
	  </td>
    <?php endif; endif; ?>
    <td>
    <?php if($this->params->get( 'dodavatel')): ?>
      <a href="<?php echo $link_dod ?>">
        <?php echo $item->fadod ?>
      </a>
      <?php else : ?>
      <?php echo $item->fadod ?>
      <?php endif; ?>
    </td>
    <?php if($this->params->get( 'ico')): ?>
    <td>
      <?php echo $item->ico ?>
    </td>
    <?php endif; ?>
    <?php if($this->params->get('adresa')): ?>
    <td>
      <?php echo $adresa.$stat ?>
    </td>
    <?php endif; ?>
    <?php if($this->params->get( 'dokumenty')): ?>
    <td class="center">
      <?php if(!empty($item->file)) { ?>
      <?php echo  jzmluvyHelper::subor_scan($item->id,$item->file,$item->filename,$item->extension,$link,$item->hits,0); }?> 
      <?php if(!empty($item->file2)) { ?>
      <?php echo  jzmluvyHelper::subor_text($item->id,$item->file2,$item->filename2,$item->extension2,$link2,$item->hits2,0); ?>
      <?php } ?>&nbsp; 
    </td>
    <?php endif; ?>
  </tr>
  <?php endif; ?>
  <?php endforeach ?>
</tbody>  
</table> 
  <input type="hidden" name="option" value="com_jzmluvy" />
  <input type="hidden" name="view" value="zmluvy" />
  <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
  <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>
<?php echo "<!-- jZmluvy ver.".$this->nastavenie->ver." STOP -->"; ?>
